package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class OrderContainer here.
 * 
 * @author (dmab0913 Gruppe4) 
 * @version (a version number or a date)
 */
public class OrderContainer
{
    private ArrayList<Order> Orders;
    private static OrderContainer instance;

    /**
     * Constructor for objects of class ItemContainer
     */
    public OrderContainer()
    {
        Orders = new ArrayList<Order>();
    }

    /**
     * Singleton for the OrderContainer class
     */
    public static OrderContainer getInstance()
    {
        if (instance == null)
        {
            instance = new OrderContainer();
            return instance;
        }
        return instance;
    }

    /**
     * puts a order-objekt into the container
     */
    public void addOrder(Order order)
    {
        Orders.add(order);
    }

    /**
     * finds a specific item-object from the container
     */
    public Order findOrder(long orderNumber)
    {
        int index = 0;
        boolean found = false;
        while(index < Orders.size() && !found)
        {
            Order order = Orders.get(index);
            if(orderNumber == order.getOrderNumber())
            {
                found = true;
            }
            else
            {
                index++;

            }
        }
        if(found)
        {
            return Orders.get(index);
        }
        else
        {
            return null;
        }
    }

    /**
     * finds and updates all the fields of a order-object except for orderNumber
     */
    public void updateOrder(long orderNumber,int date , int deliveryDate, int paymentDeadline, String status)
    {
        boolean found = false;
        int index = 0;
        while(index < Orders.size() && !found)
        {
            Order O = Orders.get(index);
            if(O.getOrderNumber() == orderNumber)
            {
                O.updateOrder(date, deliveryDate, paymentDeadline, status);
                found = true;
            }
            index++;
        }
    }
}
